<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>拖拽</title>
    <style>
        .backtop {
            position: fixed;
            right: 20px;
            bottom: 20px;
            width: 45px;
            height: 45px;
            line-height: 45px;
            text-align: center;
            background-color: rgba(0, 0, 0, 0.6);
            border-radius: 50%;
            color: #fff;
            font-size: 30px;
            -webkit-tap-highlight-color: transparent;

        }
    </style>
</head>

<body>
    <a href="###" class="backtop" id="backtop">&uarr;</a>
    <script>
        var backtop = document.getElementById('backtop')
        var curPoint = {
            x: 0,
            y: 0
        }


        function drag(el) {
            var curPoint = {
                x: 0,
                y: 0
            }
            var startPoint = {} //当前位置
            el.addEventListener('touchstart', handleStart)
            el.addEventListener('touchmove', handleMove)
            el.addEventListener('touchend', handleEnd)

            function handleStart(e) {
                var touch = e.changedTouches[0]
                startPoint.x = touch.pageX
                startPoint.y = touch.pageY
            }

            function handleMove(e) {
                var touch = e.changedTouches[0]
                var movePoint = {} //（移动后）当前位置
                var diffPoint = {} //本次移动的距离
                diffPoint.x = touch.pageX - startPoint.x
                diffPoint.y = touch.pageY - startPoint.y
                movePoint.x = diffPoint.x + curPoint.x
                movePoint.y = diffPoint.y + curPoint.y

                move(el, movePoint.x, movePoint.y)

            }

            function handleEnd(e) {
                var touch = e.changedTouches[0]
                curPoint.x += touch.pageX - startPoint.x
                curPoint.y += touch.pageY - startPoint.y

            }

            function move(e, x, y) {
                x = x || 0
                y = y || 0
                e.style.transform = 'translate3d(' + x + 'px,' + y + 'px,0)'
            }
        }
        /*  backtop.addEventListener('click', function () {
             //move(this, -10, -10)
             move(this, -10 + curPoint.x, -10 + curPoint.y)
             curPoint.x += -10
             curPoint.y += -10
         }) */
        /* function move(e, x, y) {
            x = x || 0
            y = y || 0
            e.style.transform = 'translate3d(' + x + 'px,' + y + 'px,0)'
        } */
        drag(backtop)
    </script>
</body>

</html>